<?php

namespace App\Http\Controllers\System\Testing;

use Illuminate\Http\Request;
use App\Http\Resources\Common\DataResource;
use App\Services\Postman\ApiService as PostmanApiService;

class OrderController extends Controller
{

    /**
     * 订单转入
     *
     * @param Request $request
     * @return DataResource
     */
    public function transferIn(Request $request): DataResource
    {
        list($rules, $messages) = $this->validateAccount();
        // 参数验证
        $data = $request->validate([
                'plat_code' => 'required|string',
                'currency' => 'required|string',
            ] + $rules + $this->rulesAmount(), $messages
        );
        $data += ['plat_sn' => (string)time()];

        $res = PostmanApiService::post(PostmanApiService::URI_TRANSFER_IN, $data);

        return new DataResource($res);
    }

    /**
     * 订单转出
     *
     * @param Request $request
     * @return DataResource
     */
    public function transferOut(Request $request): DataResource
    {
        list($rules, $messages) = $this->validateAccount();
        // 参数验证
        $data = $request->validate([
                'plat_code' => 'required|string',
                'currency' => 'required|string',
            ] + $rules + $this->rulesAmount(), $messages
        );
        $data += ['plat_sn' => (string)time()];

        $res = PostmanApiService::post(PostmanApiService::URI_TRANSFER_OUT, $data);

        return new DataResource($res);
    }
}
